import json
import boto3


def lambda_handler(event, context):
    sqs = boto3.client('sqs')
    queue_url = 'https://sqs.us-east-1.amazonaws.com/292220080392/Q1'

    # TODO implement
    if event['currentIntent']['name'] == 'Greeting':
        content = 'How can I help you?'
    elif event['currentIntent']['name'] == 'ThankYou':
        content = 'You’re welcome.'
    elif event['currentIntent']['name'] == 'Dining':

        try:
            location = event['currentIntent']['slots']['location']
            cuisine = event['currentIntent']['slots']['cuisine']
            nop = event['currentIntent']['slots']['nop']
            date = event['currentIntent']['slots']['date']
            time = event['currentIntent']['slots']['time']
            phone = event['currentIntent']['slots']['phone']

            # push to SQS

            data = {
                'location': location,
                'cuisine': cuisine,
                'nop': nop,
                'date': date,
                'time': time,
                'phone': phone
            }
            data = json.dumps(data)
            response = sqs.send_message(
                QueueUrl=queue_url,
                DelaySeconds=10,
                MessageAttributes={},
                MessageBody=data
            )
            content = 'You’re all set! Expect my suggestions shortly!'
        except Exception as e:
            content = str(e)

    else:
        content = 'I am not sure...'
    return {
        'sessionAttributes': {},
        'dialogAction': {
            'type': 'Close',
            'fulfillmentState': "Fulfilled",
            'message': {
                'contentType': "PlainText",
                'content': content
            }
        }
    }
